package com.kobeliu.demo_mq.mq;


import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@RabbitListener(queues = "order_queue")
public class OrderMqListener {

    @RabbitHandler
    public void messageHandler(String msg, Message message, Channel channel) {

        long deliveryTag = message.getMessageProperties().getDeliveryTag();

        System.out.println("msgTag="+deliveryTag);
        System.out.println("message="+message);
        System.out.println("msg="+msg);

        //消费完手动确认ACK
        try {

            channel.basicAck(deliveryTag,
                    false); //是否批量

            //channel.basicNack(deliveryTag,
            //        false, // 是否批量
            //        true);    //是否重新入队
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
